import requests
# from lxml import etree


class DriverRequests:
    def __init__(self, is_ssl=False):
        # self.proxies={
        #     'http':'http://127.0.0.1:8888'
        # }
        self.Is_ssl = is_ssl
        requests.packages.urllib3.disable_warnings()
        self.Resq = requests.session()
    
    def http_get_by_json(self, url, headers):
        response = self.Resq.get(url, headers=headers, verify=self.Is_ssl)
        return response.json()
        # return Response.content.decode('UTF-8')
        
    def http_post_by_json(self, url, headers, post_data):
        response = self.Resq.post(url, headers=headers, data=post_data, verify=self.Is_ssl)
        return response.json()
        # return Response.content.decode('UTF-8')
    
    def http_download_file(self, url, headers, filename):
        response = self.Resq.get(url, headers=headers, verify=self.Is_ssl)
        response.raise_for_status()
        with open(filename, 'wb') as obj:
            obj.write(response.content)
    
    # def myhttp_xpath_res(self, code, xpath):
    #     tree = etree.HTML(code)
    #     return tree.xpath(xpath)
    #
    # def Merge_List(self, key, value):
    #     return dict(zip(key, value))
